﻿using System;

namespace _12306Bot.AuthCode
{
    class MatchedTagCode : IComparable
    {
        /// <summary>
        /// 特征字符
        /// </summary>
        private char _authChar;
        public char AuthChar
        {
            get { return _authChar; }
            set { _authChar = value; }
        }
        /// <summary>
        /// 特征码在验证码上出现的位置，即命中位置
        /// </summary>
        private int _displayPosition;
        public int DisplayPosition
        {
            get { return _displayPosition; }
            set { _displayPosition = value; }
        }

        /// <summary>
        /// 命中时特征码的面积，占特征码总面积的比率
        /// </summary>
        private float _matchRate;
        public float MatchRate
        {
            get { return _matchRate; }
        }
        /// <summary>
        /// 设定命中时特征码的面积，占特征码总面积的比率。每个特征码只保留最大命中比率（每个特征码应该只能命中一次，但是为了保险起见还是加个判断）
        /// </summary>
        /// <param name="matchArea"></param>
        public void setMatchRate(int matchRate)
        {
            _matchRate = matchRate;
        }
        /// <summary>
        /// 前景像素个数，前景像素越多，匹配时越优先
        /// </summary>
        private int _pixCount;
        public int PixCount
        {
            get { return _pixCount; }
        }
        /// <summary>
        /// 命中像素比率
        /// 20121120版算法用，计算命中时，前景像素的比例
        /// </summary>
        private float _hitPixRate;
        public float HitPixRate
        {
            get { return _hitPixRate; }
            set { _hitPixRate = value; }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="authChar">特征字符</param>
        /// <param name="displayPosition">命中位置</param>
        /// <param name="hitPixRate">命中像素比率</param>
        /// <param name="pixCount">像素数</param>
        public MatchedTagCode(char authChar, int displayPosition, float hitPixRate, int pixCount)
        {
            this._authChar = authChar;
            this._displayPosition = displayPosition;
            this._hitPixRate = hitPixRate;
            this._pixCount = pixCount;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="authChar">特征字符</param>
        /// <param name="displayPosition">命中位置</param>
        /// <param name="matchRate">面积比率</param>
        /// <param name="pixCount">像素数</param>
        //public MatchedTagCode(char authChar, int displayPosition, float matchRate, int pixCount)
        //{
        //    this._authChar = authChar;
        //    this._displayPosition = displayPosition;
        //    this._matchRate = matchRate;
        //    this._pixCount = pixCount;
        //}

        public int CompareTo(Object obj)
        {
            MatchedTagCode mtc = (MatchedTagCode)obj;
            if (this.HitPixRate < mtc.HitPixRate)
            {
                return 1;
            }
            else if (this.HitPixRate == mtc.HitPixRate)
            {
                return 0;
            }
            else
            {
                return -1;
            }
        }
    }
}
